﻿using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace EFDemo.Migrations
{
    /// <inheritdoc />
    public partial class init : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.CreateTable(
                name: "Recipes",
                columns: table => new
                {
                    Id = table.Column<long>(type: "INTEGER", nullable: false)
                        .Annotation("Sqlite:Autoincrement", true),
                    Ppid = table.Column<string>(type: "TEXT", nullable: true),
                    RecipeName = table.Column<string>(type: "TEXT", nullable: true),
                    RecipeVersion = table.Column<string>(type: "TEXT", nullable: true),
                    EditVersion = table.Column<string>(type: "TEXT", nullable: true),
                    CheckNum = table.Column<string>(type: "TEXT", nullable: true),
                    RecipeState = table.Column<int>(type: "INTEGER", nullable: false),
                    CreateTime = table.Column<DateTime>(type: "TEXT", nullable: false),
                    UpdateTime = table.Column<DateTime>(type: "TEXT", nullable: false),
                    CreateBy = table.Column<string>(type: "TEXT", nullable: true),
                    UpdateBy = table.Column<string>(type: "TEXT", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_Recipes", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "RecipeTests",
                columns: table => new
                {
                    Id = table.Column<long>(type: "INTEGER", nullable: false)
                        .Annotation("Sqlite:Autoincrement", true),
                    TestName = table.Column<string>(type: "TEXT", nullable: true),
                    ReportDefectsEdgeDie = table.Column<bool>(type: "INTEGER", nullable: false),
                    SensitivityParams = table.Column<string>(type: "TEXT", nullable: true),
                    CreateTime = table.Column<DateTime>(type: "TEXT", nullable: false),
                    UpdateTime = table.Column<DateTime>(type: "TEXT", nullable: false),
                    CreateBy = table.Column<string>(type: "TEXT", nullable: true),
                    UpdateBy = table.Column<string>(type: "TEXT", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_RecipeTests", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "WaferMaps",
                columns: table => new
                {
                    Id = table.Column<long>(type: "INTEGER", nullable: false)
                        .Annotation("Sqlite:Autoincrement", true),
                    WaferMapName = table.Column<string>(type: "TEXT", nullable: true),
                    ActiveList = table.Column<string>(type: "TEXT", nullable: true),
                    ThickNess = table.Column<double>(type: "REAL", nullable: false),
                    WaferType = table.Column<int>(type: "INTEGER", nullable: false),
                    PitchX = table.Column<int>(type: "INTEGER", nullable: false),
                    PitchY = table.Column<int>(type: "INTEGER", nullable: false),
                    ShowPartialDie = table.Column<bool>(type: "INTEGER", nullable: false),
                    RecipeId = table.Column<long>(type: "INTEGER", nullable: false),
                    CreateTime = table.Column<DateTime>(type: "TEXT", nullable: false),
                    UpdateTime = table.Column<DateTime>(type: "TEXT", nullable: false),
                    CreateBy = table.Column<string>(type: "TEXT", nullable: true),
                    UpdateBy = table.Column<string>(type: "TEXT", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_WaferMaps", x => x.Id);
                    table.ForeignKey(
                        name: "FK_WaferMaps_Recipes_RecipeId",
                        column: x => x.RecipeId,
                        principalTable: "Recipes",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "SamplePlans",
                columns: table => new
                {
                    Id = table.Column<long>(type: "INTEGER", nullable: false)
                        .Annotation("Sqlite:Autoincrement", true),
                    SpEdgeExclusion = table.Column<int>(type: "INTEGER", nullable: false),
                    PrimaryThresholdDies = table.Column<string>(type: "TEXT", nullable: true),
                    SecondaryThresholdDies = table.Column<string>(type: "TEXT", nullable: true),
                    NotInspectDies = table.Column<string>(type: "TEXT", nullable: true),
                    TestId = table.Column<long>(type: "INTEGER", nullable: false),
                    RecipeTestId = table.Column<long>(type: "INTEGER", nullable: true),
                    CreateTime = table.Column<DateTime>(type: "TEXT", nullable: false),
                    UpdateTime = table.Column<DateTime>(type: "TEXT", nullable: false),
                    CreateBy = table.Column<string>(type: "TEXT", nullable: true),
                    UpdateBy = table.Column<string>(type: "TEXT", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_SamplePlans", x => x.Id);
                    table.ForeignKey(
                        name: "FK_SamplePlans_RecipeTests_RecipeTestId",
                        column: x => x.RecipeTestId,
                        principalTable: "RecipeTests",
                        principalColumn: "Id");
                });

            migrationBuilder.CreateIndex(
                name: "IX_SamplePlans_RecipeTestId",
                table: "SamplePlans",
                column: "RecipeTestId");

            migrationBuilder.CreateIndex(
                name: "IX_WaferMaps_RecipeId",
                table: "WaferMaps",
                column: "RecipeId");
        }

        /// <inheritdoc />
        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropTable(
                name: "SamplePlans");

            migrationBuilder.DropTable(
                name: "WaferMaps");

            migrationBuilder.DropTable(
                name: "RecipeTests");

            migrationBuilder.DropTable(
                name: "Recipes");
        }
    }
}
